﻿//  Copyright (c) 2011 Ray Liang (http://www.dotnetage.com)
//  Licensed MIT: http://www.opensource.org/licenses/mit-license.php

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DNA.OpenAPI.Rss;

namespace DNA.Mvc.Services
{
    public abstract class RssItemsGeneratorBase : Command
    {
        protected abstract IEnumerable<RssItem> OnCreateRssItems(IDictionary<string, object> data);

        public override void Execute(CommandContext context)
        {
            var items = OnCreateRssItems(context.Data);
            if ((items != null) && (items.Count() > 0))
            {
                ((RssDocument)context.Bag).Channel.Items.AddRange(items);
            }
        }
    }
}
